<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%--获取流水号--%>
<script>
    var xm_fieldid_dt1 = WfForm.convertFieldNameToId("xm", "detail_1");
    var jbrq_fieldid_dt1 = WfForm.convertFieldNameToId("jbrq", "detail_1");
    var jbjsrq_fieldid_dt1 = WfForm.convertFieldNameToId("jbjsrq", "detail_1");
    var jbkssj_fieldid_dt1 = WfForm.convertFieldNameToId("jbkssj", "detail_1");
    var jbjssj_fieldid_dt1 = WfForm.convertFieldNameToId("jbjssj", "detail_1");

    WfForm.registerCheckEvent(WfForm.OPER_SAVE + "," + WfForm.OPER_SUBMIT, function (callback) {
        var count = 0;
        var msg = "";
        var arr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
        for (var i = 0; i < arr.length; i++) {
            var xm_value = WfForm.getFieldValue(xm_fieldid_dt1 + "_" + arr[i]);
            var jbrq_value = WfForm.getFieldValue(jbrq_fieldid_dt1 + "_" + arr[i]);
            var jbjsrq_value = WfForm.getFieldValue(jbjsrq_fieldid_dt1 + "_" + arr[i]);
            var jbkssj_value = WfForm.getFieldValue(jbkssj_fieldid_dt1 + "_" + arr[i]);
            var jbjssj_value = WfForm.getFieldValue(jbjssj_fieldid_dt1 + "_" + arr[i]);
            var datas = getKqToResource(xm_value,jbjsrq_value);
            if(jbkssj_value<datas.begtime){
                count++;
                msg = "明细表第"+arr[i]+"行加班开始时间小于上班开始时间";
            }
        }
         if(count>0){
             alert(msg);
         }else {
             callback();
         }

    });


    function getKqToResource(userid,jbjsrq_value) {
        var datas = '';
        $.ajax({
            type: "get",
            async: false,
            url: "/interface/hoda/getKqToResource_Ajax.jsp",
            dataType: 'json',
            data: {userid: userid,begdate:jbjsrq_value},
            success: function (data) {
                datas = data;
            }
        });
        return datas;
    }
</script>
<%
    RecordSet rs = new RecordSet();
    BaseBean baseBean = new BaseBean();
    JSONObject jsonData = new JSONObject();
    String userid = Util.null2String( request.getParameter( "userid" ) );
    baseBean.writeLog(">>>>getKqToResource_Ajax>>>userid="+userid);
    String groupid = getGroupidByResourceid(userid);
    baseBean.writeLog(">>>>getKqToResource_Ajax>>>groupid="+groupid);
    String serialid = getSerialidByGroupid(groupid);
    baseBean.writeLog(">>>>getKqToResource_Ajax>>>serialid="+serialid);
    rs.executeQuery("select t.id,t1.times,t1.onoffworktype from kq_ShiftManagement t join kq_ShiftOnOffWorkSections t1 on \n" +
            "t.id=t1.serialid where t.id=?", serialid );
    while (rs.next()) {
        String times = Util.null2String( rs.getString( "times" ) );
        String onoffworktype = Util.null2String( rs.getString( "onoffworktype" ) );
        if ("start".equals( onoffworktype )) {
            jsonData.put( "begtime", times );
        }
        if ("end".equals( onoffworktype )) {
            jsonData.put( "endtime", times );
        }
    }
    baseBean.writeLog(">>>>getKqToResource_Ajax>>>jsonData="+jsonData.toJSONString());
    out.print( jsonData.toJSONString() );
%>
<%!
    public static String getGroupidByResourceid(String userid){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select groupid kq_groupmember where typevalue=?", userid );
        rs.next();
        return Util.null2String(rs.getString(1));
    }
    public static String getSerialidByGroupid(String groupid){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select serialid from kq_fixedschedulce where groupid=? and weekday <=4 group by serialid", groupid );
        rs.next();
        return Util.null2String(rs.getString(1));
    }
%>